package com.zqxq.lottery.controller.user;

import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.entity.vo.user.UserInfoVO;
import com.zqxq.lottery.service.user.IUserInfoService;
import com.zqxq.lottery.service.user.IUserSignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/sign")
public class UserSignController{

    @Autowired
    private IUserSignService userSignService;
    @Autowired
    private IUserInfoService userInfoService;
    //分页查询列表
    @PostMapping("/reward")
    public Result signReward(@RequestParam("userId") Long userId){
        Result rs = new Result();
        if(userId == null){
            return new Result(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        UserInfoVO userInfoVO = userInfoService.getVO(userId);
        if(userInfoVO == null){
            return new Result(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        try{
            rs = userSignService.signReward(userId);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("User Sign Reward Error:",e);
        }
        return rs;
    }

}
